Component({
  properties:{
    goodsItem:{
      type:Array,
      value: []
    }
  },
  data:{
  },
  methods:{
    addGoods:function(e){
      console.log(this.__data__.goodsItem)
      var goodsItem = this.__data__.goodsItem;
      console.log(e.target.dataset.id)
      var goodId,img,name,unit,unit2,price,oldPrice;
      for (var i = 0; i < goodsItem.length;i++){
        if (i == e.target.dataset.id){
          img = goodsItem[i].img;
          goodId = goodsItem[i].id;
          name = goodsItem[i].name;
          unit = goodsItem[i].unit;
          unit2 = goodsItem[i].unit2;
          price = goodsItem[i].price;
          oldPrice = goodsItem[i].oldPrice;
        }
      }
      wx.request({
        url: 'http://127.0.0.1:8080/insertGoods',
        data: {
          goodId: goodId, img: img, name: name,
          num: 20, unit: unit, unit2: unit2, price: price,
          oldPrice: oldPrice},
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          wx.showToast({
            title: '加入购物车成功'
          });
        }
      })
    }
  }
})